package com.mkyong.core;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringWriter;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
	public static void main(String[] args) {
//		springInit();
		velocityTest();
	}


	private static void springInit() {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"SpringBeans.xml");

		HelloWorld obj = (HelloWorld) context.getBean("helloBean");
		obj.printHello();
		obj.printHelloWorld1();
		HelloWorld1 obj1 = (HelloWorld1) context.getBean("helloWorld1");
		obj1.printHello();
		Singer singer = (Singer) context.getBean("singer");
		
		String resourcePath = App.class.getResource("/resources/ibatis/mysql/PersonMapper.xml").getPath();
		System.out.println("resourcePath="+resourcePath);
	}
	
	
	public static void velocityTest(){
		
		Velocity ve = new Velocity();
		ve.init();
		Template template = ve.getTemplate("./src/main/resources/a.vm");
		
		VelocityContext context = new VelocityContext();
		context.put("name", "zhangsan");
		context.put("msg", "Hello");
		
//		StringWriter writer = new StringWriter();
		OutputStreamWriter writer = new OutputStreamWriter(System.out);

		template.merge(context, writer);
		
		try {
			writer.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	
	
	
}
